﻿
CREATE PROCEDURE [dbo].[P_OBTERLISTA_T04_PEDIDO]
	@cd_pedido [int]
   ,@cd_quarto [int]
   ,@dt_pedido [datetime]
   
AS
BEGIN
	SELECT
	T.cd_pedido
    ,T.cd_quarto
    ,T.dt_pedido
    ,T7.ds_identificacao DS_QUARTO
    ,T8.cd_predio CD_PREDIO
    ,T8.ds_identificacao DS_PREDIO
  FROM T04_PEDIDO T
  INNER JOIN T07_QUARTO T7 ON T.cd_quarto = T7.cd_quarto
  INNER JOIN T08_PREDIO T8 ON T7.cd_predio = T8.cd_predio
  WHERE
    (T.cd_pedido = @cd_pedido OR @cd_pedido IS NULL)
    AND (T.cd_quarto = @cd_quarto OR @cd_quarto IS NULL)
    AND (T.dt_pedido = @dt_pedido OR @dt_pedido IS NULL)
    
END